package com.Smart.smartscals.DataBase;



import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;

/*
 * SharedPreferences鍙傛暟绠＄悊绫伙紝
 * 鍔熻兘锛歋haredPreferences 鍙傛暟璇诲彇锛屼慨鏀圭瓑
 * @author wutl
 * 2013-09-16-08-59
 * */


public class SharedParam {
	
	private static final String SPNAME = "dealWithData";
	private SharedPreferences mPreferences;
	private Editor mEditor;
	private Resources rs;
	private static final String USERNAME = "userName";
	private static final String USERID = "userId";


	private static SharedParam mParam = null;
	
	private SharedParam(Context context){
		//this.mContext = context;
		this.mPreferences = context.getSharedPreferences(SPNAME, Context.MODE_PRIVATE);	
		rs = context.getResources();
	}
	
	public static SharedParam getInstance(Context context){
		if(mParam==null){
			mParam = new SharedParam(context); 
		}
		return mParam;
	}

	/**
	 * 获得当前用户的userName
	 * @return
	 */
	public String getActiveUserName() {
		return mPreferences.getString(USERNAME,null);
	}
	/**
	 * 保存当前用户的userName,在登录或者是注册的时候调用
	 * @param userName
	 */
	public void setActiveUserName(String userName){
		mEditor = mPreferences.edit();
		mEditor.putString(USERNAME, userName);
		mEditor.commit();
	}
	/**
	 * 获取当前用户的userId
	 * @return
	 */
	public String getCurrentUserId(){
		return mPreferences.getString(USERID,null);
	}
	/**
	 * 保存当前用户的userId,在用用户登录的时候就把这个值保存下来
	 * @param userId
	 */
	public void setCurrentUserId(String userId){
		mEditor = mPreferences.edit();
		mEditor.putString(USERID, userId);
		mEditor.commit();
	}
	
	
}
